package com.yinhai.message.manage.wxregister.bpo;

import java.util.List;

import com.yinhai.core.service.ta3.domain.service.TaBaseService;
import com.yinhai.message.api.bean.TMWeChat;
import com.yinhai.message.manage.wxregister.dao.IWxConfigDao;
import com.yinhai.message.manage.wxregister.po.WxConfigPo;
import com.yinhai.message.manage.wxregister.vo.WxConfigVo;

/**
 * 
 * @author yanglq
 * 2017.5.2
 */
public class WxConfigBpoImpl extends TaBaseService implements IWxConfigBpo{

	private IWxConfigDao wxConfigDao;
	public void setWxConfigDao(IWxConfigDao wxConfigDao) {
		this.wxConfigDao = wxConfigDao;
	}
	
	@Override
	public List<WxConfigVo> queryWxList(String appid, String name) {
		return wxConfigDao.queryWxList(appid, name);
	}

	@Override
	public void addWx(WxConfigPo po) {
		String defaultwx = po.getDefaultwx();
		if("1".equals(defaultwx)){
			wxConfigDao.removeDefault();
		}else{
			po.setDefaultwx("0");
		}
		wxConfigDao.saveWx(po);
	}

	@Override
	public void modifyWx(WxConfigPo po) {
		String defaultwx = po.getDefaultwx();
		if("1".equals(defaultwx)){
			wxConfigDao.removeDefault();
		}else{
			po.setDefaultwx("0");
		}
		wxConfigDao.updateWx(po);
	}

	@Override
	public void removeWx(Long id) {
		wxConfigDao.removeWx(id);
	}

	@Override
	public TMWeChat getDefaultWx() {
		TMWeChat wx= new TMWeChat();
		WxConfigPo po = wxConfigDao.getDefaultWx();
		wx.setAppid(po.getAppid());
		wx.setSecret(po.getSecret());
		return wx;
	}

}
